package dao.impl;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import dao.CarTypeDao;
import po.car.CarType;

public class CarTypeDaoImpl implements CarTypeDao{
	private List<CarType> types;
	

	public CarTypeDaoImpl() {
		types = new LinkedList<>();
	}

	@Override
	public boolean insert(Object t) {
		if(types.contains(t)) {
			return false;
		}
		return types.add((CarType) t);
	}

	@Override
	public boolean update(Object t) {
		int index = types.indexOf(t);
		if(index == -1) {
			return false;
		}else {
			types.set(index, (CarType) t);
			return true;
		}
	}

	@Override
	public boolean delete(int id) {
		Iterator<CarType> it = types.iterator();
		while (it.hasNext()) {
			CarType car = (CarType) it.next();
			if (car.getTypeId() == id) {
				it.remove();
				return true;
			}
		}
		return false;
	}

	@Override
	public Object selectById(int id) {
		for (CarType c : types) {
			if(c.getTypeId() == id) {
				return c;
			}
		}
		return null;
	}

	@Override
	public List selectAll() {
		List<CarType> copy = new LinkedList<CarType>();
		return copy;
	}

}
